package com.ruoyi.project.wodemand.controller;

import java.util.List;

import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.security.service.TokenService;
import com.ruoyi.project.hr.domain.THrContractinfo;
import com.ruoyi.project.wodemand.domain.TLogicCode;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wodemand.domain.TCondtionJudge;
import com.ruoyi.project.wodemand.service.ITCondtionJudgeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 逻辑条件Controller
 *
 * @author lt
 * @date 2020-04-21
 */
@RestController
@RequestMapping("/wodemand/JUDGE")
public class TCondtionJudgeController extends BaseController
{
    @Autowired
    private ITCondtionJudgeService tCondtionJudgeService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询逻辑条件列表
     */
    @PreAuthorize("@ss.hasPermi('wodemand:JUDGE:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCondtionJudge tCondtionJudge)
    {
        startPage();
        List<TCondtionJudge> list = tCondtionJudgeService.selectTCondtionJudgeList(tCondtionJudge);
        return getDataTable(list);
    }

    /**
     * 导出逻辑条件列表
     */
    @PreAuthorize("@ss.hasPermi('wodemand:JUDGE:export')")
    @Log(title = "逻辑条件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TCondtionJudge tCondtionJudge)
    {
        List<TCondtionJudge> list = tCondtionJudgeService.selectTCondtionJudgeList(tCondtionJudge);
        ExcelUtil<TCondtionJudge> util = new ExcelUtil<TCondtionJudge>(TCondtionJudge.class);
        return util.exportExcel(list, "JUDGE");
    }

    /**
     * 获取逻辑条件详细信息
     */
    @PreAuthorize("@ss.hasPermi('wodemand:JUDGE:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tCondtionJudgeService.selectTCondtionJudgeById(id));
    }

    /**
     * 新增逻辑条件
     */
    @PreAuthorize("@ss.hasPermi('wodemand:JUDGE:add')")
    @Log(title = "逻辑条件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCondtionJudge tCondtionJudge)
    {
        return toAjax(tCondtionJudgeService.insertTCondtionJudge(tCondtionJudge));
    }

    /**
     * 修改逻辑条件
     */
    @PreAuthorize("@ss.hasPermi('wodemand:JUDGE:edit')")
    @Log(title = "逻辑条件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCondtionJudge tCondtionJudge)
    {
        return toAjax(tCondtionJudgeService.updateTCondtionJudge(tCondtionJudge));
    }

    /**
     * 删除逻辑条件
     */
    @PreAuthorize("@ss.hasPermi('wodemand:JUDGE:remove')")
    @Log(title = "逻辑条件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCondtionJudgeService.deleteTCondtionJudgeByIds(ids));
    }

    @Log(title = "外包公司导入", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TCondtionJudge> util = new ExcelUtil<TCondtionJudge>(TCondtionJudge.class);
        List<TCondtionJudge> list = util.importExcel(file.getInputStream());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        String message = tCondtionJudgeService.importJudge(list, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<TCondtionJudge> util = new ExcelUtil<TCondtionJudge>(TCondtionJudge.class);
        return util.importTemplateExcel("判断依据导入模板");
    }

}
